package com.dhcc.sdc.cdss.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.dhcc.core.framework.base.controller.BaseController;
import com.dhcc.core.framework.base.warpper.EmptyWarpper;
import com.dhcc.core.framework.exception.BizException;
import com.dhcc.core.framework.exception.BizExceptionEnum;
import com.dhcc.core.framework.result.R;
import com.dhcc.core.framework.result.page.PageFactory;
import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.sdc.cdss.entity.SdcCdssItemStageDicEntity;
import com.dhcc.sdc.cdss.service.ISdcCdssItemStageDicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;


/**
 * 诊疗阶段
 * 
 * @ClassName: SdcCdssItemStageDicController
 * @Description: TODO
 * @author sunyingjie
 * @date 2023-04-06 10:25:59
 */
@Controller
@RequestMapping("${sys.backendPath}/sdc/sdccdssitemstagedic")
public class SdcCdssItemStageDicController extends BaseController {

	private String PREFIX = "/backend/cdss/sdccdssitemstagedic/";

	@Autowired
	private ISdcCdssItemStageDicService sdcCdssItemStageDicService;
	

    /**
     * 跳转到诊疗阶段列表首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "sdccdssitemstagedic.html";
    }
	
    /**
     * 跳转到新增诊疗阶段
     */
    @RequestMapping("/to_add")
    public String toAdd() {
        return PREFIX + "sdccdssitemstagedic_add.html";
    }
	
	/**
     * 跳转到修改诊疗阶段
     */
    @RequestMapping("/to_update/{sdcCdssItemStageDicId}")
    public String toUpdate(@PathVariable Integer sdcCdssItemStageDicId, Model model) {
        SdcCdssItemStageDicEntity sdcCdssItemStageDic = this.sdcCdssItemStageDicService.selectById(sdcCdssItemStageDicId);
        model.addAttribute("sdcCdssItemStageDic",sdcCdssItemStageDic);
        return PREFIX + "sdccdssitemstagedic_edit.html";
    }

    /**
     * 获取诊疗阶段列表
     */
	@SuppressWarnings("unchecked")
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam Map<String, Object> params) {
		Page<SdcCdssItemStageDicEntity> page = new PageFactory<SdcCdssItemStageDicEntity>().defaultPage();
        List<SdcCdssItemStageDicEntity> result = this.sdcCdssItemStageDicService.page(page,params);
        page.setRecords((List<SdcCdssItemStageDicEntity>) new EmptyWarpper(result).warp());
        return R.packForBT(page);
    }

    /**
     * 新增诊疗阶段
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(SdcCdssItemStageDicEntity sdcCdssItemStageDic) {
        if (CommonUtil.isOneEmpty(sdcCdssItemStageDic)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.sdcCdssItemStageDicService.insert(sdcCdssItemStageDic);
        return R.ok();
    }

    /**
     * 删除诊疗阶段
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer sdcCdssItemStageDicId) {
	
        this.sdcCdssItemStageDicService.deleteById(sdcCdssItemStageDicId);

        return R.ok();
    }

    /**
     * 修改诊疗阶段
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(SdcCdssItemStageDicEntity sdcCdssItemStageDic) {
        if (CommonUtil.isOneEmpty(sdcCdssItemStageDic)) {
            throw new BizException(BizExceptionEnum.REQUEST_NULL);
        }
        this.sdcCdssItemStageDicService.updateById(sdcCdssItemStageDic);
        return R.ok();
    }
	
}
